#include "LineEdit_ThermostatTemperature.h"

#include "QRegExp.h"
#include "QValidator.h"

LineEdit_ThermostatTemperature::LineEdit_ThermostatTemperature(QWidget *parent)
	: QLineEdit(parent)
{
	QRegExp regExp("^(\\d+)(\\.\\d+)?$");
	setValidator(new QRegExpValidator(regExp, this));
	connect(this, &LineEdit_ThermostatTemperature::editingFinished, this, &LineEdit_ThermostatTemperature::slot_thermostatTemperatureLineEditFinished);
}

LineEdit_ThermostatTemperature::~LineEdit_ThermostatTemperature()
{
}
float LineEdit_ThermostatTemperature::getTemperature()
{
	QString value = text();
	if (value.isEmpty())
	{
		return 0;
	}
	else
	{
		return value.toFloat();
	}
}
void LineEdit_ThermostatTemperature::setTemperature(float temperature)
{
	setText(QString::number(temperature,'f',accuracy));
}
void LineEdit_ThermostatTemperature::slot_thermostatTemperatureLineEditFinished()
{
	if (text().isEmpty())
	{
		setText(QString::number(0));
		return;
	}
}

int LineEdit_ThermostatTemperature::getAccuracy()
{
	return accuracy;
}
void LineEdit_ThermostatTemperature::setAccuracy(int accuracy)
{
	this->accuracy = accuracy;
}